// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/index'
import 'amfe-flexible'
import axios from './assets/js/axios'
import wx from 'weixin-js-sdk'
import VConsole from 'vconsole'
import Vant, {Lazyload} from 'vant'
import 'vant/lib/index.css'

Vue.use(Vant).use(Lazyload)

Vue.config.productionTip = false
Vue.prototype.$http = axios

router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  next()
})
router.afterEach((to,from)=>{
  // 非微信浏览器跳转到此页 - notWechat
  if(!/MicroMessenger/i.test(navigator.userAgent) && to.name.indexOf('notWechat')==-1){
    window.location.href = '/#/notWechat';
    return
  }else if(to.name.indexOf('notWechat')!=-1){
    return
  }
})

//权限注入
axios.post('/getsignature').then(async res=>{
  // console.log('获取权限注入信息')
  await wx.config({
    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
    appId: res.data.appId, // 必填，公众号的唯一标识
    timestamp: res.data.timestamp, // 必填，生成签名的时间戳
    nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
    signature: res.data.signature, // 必填，签名
    jsApiList: ["onMenuShareAppMessage", "onMenuShareTimeline", "chooseWXPay"] // 必填，需要使用的JS接口列表
  });
  wx.error(res=> {
    console.log('wx-error',res)
  });
})

//如果不是生产环境 显示调试
if (process.env.NODE_ENV != "production") {
  console.log(process.env.NODE_ENV);
  const vConsole = new VConsole();
}

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
})
